package com.sskj.asset.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.asset.bean.ExchangeHistoryEntry;
import com.sskj.asset.http.HttpConfig;
import com.sskj.asset.ui.activity.CashRecordActivity;
import com.sskj.common.base.HttpData;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonConverter;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Flowable;


public class CashRecordActivityPresenter extends BasePresenter<CashRecordActivity> {
    /**
     * 获取可兑换币种
     */
    public Flowable<List<ExchangeHistoryEntry.Entry>> getHistory(int page, int size) {
        return OkGo.<HttpData<PageBean<ExchangeHistoryEntry.Entry>>>get(HttpConfig.BASE_URL + HttpConfig.EXCHANE_HISTORY)
                .params("page", page)
                .params("size", size)
                .converter(new JsonConverter<HttpData<PageBean<ExchangeHistoryEntry.Entry>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(exchangeHistoryEntryHttpData -> exchangeHistoryEntryHttpData.getData().getList())
                .onErrorReturnItem(new ArrayList<>());
    }

}
